/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package com.xjrsoft.module.bi.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xjrsoft.common.model.result.R;
import com.xjrsoft.module.bi.common.constant.LauncherConstant;
import com.xjrsoft.module.bi.common.tool.Condition;
import com.xjrsoft.module.bi.common.tool.Func;
import com.xjrsoft.module.bi.common.tool.JsonUtil;
import com.xjrsoft.module.bi.log.DataLog;
import com.xjrsoft.module.bi.pojo.entity.VisualMap;
import com.xjrsoft.module.bi.pojo.vo.VisualMapVO;
import com.xjrsoft.module.bi.service.IVisualMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 可视化地图配置模块 控制器
 *
 * @author BladeX
 */
@RestController
@AllArgsConstructor
@RequestMapping(LauncherConstant.APPLICATION_VISUAL_NAME + "/map")
@Api(value = "可视化地图配置模块")
public class VisualMapController  {

	private final IVisualMapService visualMapService;

	/**
	 * 详情
	 */
	@DataLog("地图详情")
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情")
	public R detail(VisualMap visualMap) {
		VisualMap detail = visualMapService.getOne(Condition.getQueryWrapper(visualMap));
		return R.ok(detail);
	}

	/**
	 * 数据详情
	 */
	@DataLog("地图数据")
	@GetMapping("/data")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "数据详情")
	public Map<String, Object> data(Long id) {
		VisualMap detail = visualMapService.getById(id);
		return JsonUtil.toMap(detail.getData());
	}

	/**
	 * 可视化地图懒加载列表
	 */
	@DataLog("地图列表")
	@GetMapping("/lazy-list")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "懒加载列表")
	public R lazyList(@RequestParam String parentId, String name) {
		List<VisualMapVO> list = visualMapService.lazyList(parentId, name);
		return R.ok(list);
	}

	/**
	 * 新增 可视化地图配置表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增")
	public R save(@Valid @RequestBody VisualMap visualMap) {
		return R.ok(visualMapService.submit(visualMap));
	}

	/**
	 * 修改 可视化地图配置表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改")
	public R update(@Valid @RequestBody VisualMap visualMap) {
		return R.ok(visualMapService.submit(visualMap));
	}


	/**
	 * 删除 可视化地图配置表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "删除")
	public R remove( @RequestParam String ids) {
		return R.ok(visualMapService.removeByIds(Func.toLongList(ids)));
	}


}
